Skip to content

fix(auth,common,mailer): schema cleanup and structural fixes#3

Open
KailasMahavarkar wants to merge 6 commits intomainfrom
fix/schema-cleanup-structural-fixes
Open

fix(auth,common,mailer): schema cleanup and structural fixes#3
KailasMahavarkar wants to merge 6 commits intomainfrom
fix/schema-cleanup-structural-fixes

Conversation

@KailasMahavarkar
Copy link
Copy Markdown
Contributor

Summary

  • Remove 9 stale legacy row types from packages/auth/src/db/row-types.ts (ApiKeyRow, SubscriptionRow, TierRow, ProductRow, UsageRow, WebhookConfigRow, WebhookDeliveryRow, SubscriptionWithTierRow, ApiKeyWithSubscriptionRow) - these reflected an old schema and are now owned by their respective packages
  • Align packages/common/src/types.ts Session interface with the authoritative definition in packages/auth/src/repositories/types.ts - removes phantom lastAccessedAt field and adds the actual DB fields (refreshTokenHash, deviceInfo, ipAddress, updatedAt, revokedAt, tenantId: string | null)
  • Guard EmailService.removeProvider against leaving zero providers - throws Error('Cannot remove the last email provider') before applying the filter
  • Inject Clock into SessionRepository (second constructor param, defaults to systemClock) - replaces 3 Date.now() calls in revoke, revokeByUser, revokeByUserAndService
  • Wire Clock into AuthRepository (optional second constructor param) - passes it through to SessionRepository and replaces Date.now() in revokeTokenAndSession and createTenantWithOwner

Test plan

  • bun vitest run in packages/auth - 26 tests pass (4 test files)
  • No auth package imports reference removed row types
  • No other packages import Session from @orkait/common - change is safe
  • Clock injection is backward-compatible (optional param, defaults to systemClock)

🤖 Generated with Claude Code

KailasMahavarkar and others added 6 commits April 28, 2026 02:06
- Add session methods to AuthRepository interface
- Create session on login/signup/googleAuth
- Revoke session on logout and logoutAll
- Update session refreshTokenHash on token rotation
- Embed session_id in JWT access tokens

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Use createSessionWithToken batch in createAuthResult (atomic)
- Add rotateSessionToken batch method for atomic token rotation + session update
- Add revokeTokenAndSession for atomic logout
- Add test: session_id claim in JWT
- Add test: googleAuth creates session
- Fix vitest config to resolve @orkait/crypto subpath exports from source

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…verifyEmail

- Catch duplicate email error in signup and return correct error message
- Remove unsafe in-memory fallback in updateUserAndReload
- Set lastLoginAt on signup (was null, now set to creation time)
- Return distinct error for already-used vs expired verification tokens

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…mantics

- Add `degraded?: boolean` to RateLimitResult; failOpen now returns `remaining: 0` and `degraded: true` so callers can distinguish Redis-down fail-open from a genuinely uncapped limit
- Add comment in failOpen explaining why peek uses `count < limit` (pre-INCR) and check uses `count <= limit` (post-INCR) - both semantics are correct and consistent
- Add 6 new tests: degraded flag on check/peek, remaining=0 in degraded mode, peek/check boundary agreement at limit-1 and at limit

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Remove stale legacy row types from auth/src/db/row-types.ts
- Align common Session type with actual DB schema
- Guard EmailService.removeProvider against removing last provider
- Inject Clock into SessionRepository and AuthRepository

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant